using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace offline2048
{
    public class ConfigManager : MonoSingleton<ConfigManager>
    {
        public string UILanguageFilePath = "Assets/PrivateFiles/Scripts/Runtime/Config/xml/UILanguage.csv";
        public string ShopFilePath = "Assets/PrivateFiles/Scripts/Runtime/Config/xml/Shop.csv";
        public string CashRwardConfigFilePath = "Assets/PrivateFiles/Scripts/Runtime/Config/xml/CashRwardConfig.csv";
        //===================================================================================================
        public List<CfgUILanguage> m_LanguagesDataList = new List<CfgUILanguage>();
        public List<CfgShop> m_ShopDataList;
        public List<CfgCashRewardConfig> m_CashRwardConfigDataList;
        public void Init()
        {
            m_LanguagesDataList = ReadCfgUILanguageExcelFile();
            m_ShopDataList = ReadCfgShopExcelFile();
            m_CashRwardConfigDataList = ReadCashRwardConfigExcelFile();
        }

        public string GetTextByID(string id)
        {
            for (int i = 0; i < m_LanguagesDataList.Count; i++)
            {
                if (m_LanguagesDataList[i].id.Equals(id))
                {
                    return m_LanguagesDataList[i].word;
                }
            }
            return id;
        }
        
        public CfgShop GetShopData(string id)
        {
            for (int i = 0; i < m_ShopDataList.Count; i++)
            {
                if (m_ShopDataList[i].id.Equals(id))
                {
                    return m_ShopDataList[i];
                }
            }
            return null;
        }

        public CfgShop GetShopDataByIapKey(string iapKey)
        {
            for (int i = 0; i < m_ShopDataList.Count; i++)
            {
                if (m_ShopDataList[i].IAP_Key.Equals(iapKey))
                {
                    return m_ShopDataList[i];
                }
            }
            return null;
        } 
        
        public CfgCashRewardConfig GetCfgCashRwardConfig(string id)
        {
            for (int i = 0; i < m_CashRwardConfigDataList.Count; i++)
            {
                if (m_CashRwardConfigDataList[i].id.Equals(id))
                {
                    return m_CashRwardConfigDataList[i];
                }
            }
            return null;
        }
        
        List<CfgCashRewardConfig> ReadCashRwardConfigExcelFile()
        {
            List<CfgCashRewardConfig> cashRwards = new List<CfgCashRewardConfig>();

            /*if (!File.Exists(CashRwardConfigFilePath))
            {
                Debug.LogError($"File not found: {CashRwardConfigFilePath}");
                return cashRwards;
            }*/

            //string[] lines = File.ReadAllLines(Path.Combine(CashRwardConfigFilePath));
            for (int i = 0; i < CashRwardConfigData.Length; i++)
            {
                string[] _dataStr = CashRwardConfigData[i].Split(',');
                CfgCashRewardConfig _data = new CfgCashRewardConfig();
                _data.id = _dataStr[0];
                _data.CashRewardsType = int.Parse(_dataStr[1]);
                _data.redeemCashCd = int.Parse(_dataStr[2]);
                _data.redeemCashRewarded = int.Parse(_dataStr[3]);
                _data.redeemCashIapKey1 = _dataStr[4];
                _data.redeemCashIapKey2 = _dataStr[5];
                _data.redeemCashIapKey3 = _dataStr[6];
                _data.redeemCashIapKey4 = _dataStr[7];
                _data.PlatformFeeRate = _dataStr[8];
                _data.ReceiptAmount = _dataStr[9];
                _data.LimitDiscounts = _dataStr[10];
                _data.SaveCost = _dataStr[11];
                _data.TotalFee = _dataStr[12];
                cashRwards.Add(_data);
            }
            return cashRwards;
        }
        
        List<CfgShop> ReadCfgShopExcelFile()
        {
            List<CfgShop> cfgShops = new List<CfgShop>();

            /*if (!File.Exists(ShopFilePath))
            {
                Debug.LogError($"File not found: {ShopFilePath}");
                return cfgShops;
            }*/

            //string[] lines = File.ReadAllLines(Path.Combine(ShopFilePath));
            for (int i = 0; i < ShopData.Length; i++)
            {
                string[] _dataStr = ShopData[i].Split(',');
                CfgShop _data = new CfgShop();
                _data.id = _dataStr[0];
                _data.IAP_Key = _dataStr[1];
                _data.Title = _dataStr[2];
                _data.Name = _dataStr[3];
                _data.Description = _dataStr[4];
                _data.Prices = float.Parse(_dataStr[5]);
                _data.GoodsNum = int.Parse(_dataStr[6]);
                cfgShops.Add(_data);
            }
            return cfgShops;
        }
        
        List<CfgUILanguage> ReadCfgUILanguageExcelFile()
        {
            List<CfgUILanguage> cfgUILanguages = new List<CfgUILanguage>();

            /*if (!File.Exists(UILanguageFilePath))
            {
                Debug.LogError($"File not found: {UILanguageFilePath}");
                return cfgUILanguages;
            }*/

            //string[] lines = File.ReadAllLines(Path.Combine(UILanguageFilePath));
            for (int i = 0; i < UILanguageData.Length; i++)
            {
                string[] _dataStr = UILanguageData[i].Split(',');
                CfgUILanguage _stageData = new CfgUILanguage();
                _stageData.id = _dataStr[0];
                _stageData.word = _dataStr[1];
                cfgUILanguages.Add(_stageData);
            }
            return cfgUILanguages;
        }

        public string[] ShopData =
        {
            "1,2048charge_pack_08,Charge Pack 1000,Charge Pack 1000,Get a medium coin pack,0.99,1900",
            "2,2048charge_pack_3,Charge Pack 2000,Charge Pack 2000,Get a small coin pack,2.99,5900",
            "3,2048charge_pack_5,Charge Pack 3000,Charge Pack 3000,Get a large coin pack,4.99,9900",
            "4,2048charge_pack_8,Charge Pack 4000,Charge Pack 4000,Get a big bundle,7.99,15900",
            "5,2048charge_pack_15,Charge Pack 5000,Charge Pack 5000,Get a super bundle,14.99,29900",
            "6,2048charge_pack_25,Charge Pack 6000,Charge Pack 6000,Get a huge bundle,24.99,49900",
            "7,2048charge_pack_30,Charge Pack 7000,Charge Pack 7000,Get a mega bundle,29.99,59900",
            "8,2048charge_pack_39,Charge Pack 8000,Charge Pack 8000,Get a ultimate bundle,39.99,79900"
        };

        public string[] CashRwardConfigData =
        {
            "1,1000,86400,50,2048charge_pack_3,2048charge_pack_08,2048charge_pack_8,2048charge_pack_5,1.50%,$15.00,40%,$6.01,$7.99", 
            "2,2000,86400,50,2048charge_pack_3,2048charge_pack_08,2048charge_pack_15,2048charge_pack_5,1.50%,$30.00,50%,$15.01,$14.99", 
            "3,3000,86400,50,2048charge_pack_3,2048charge_pack_08,2048charge_pack_25,2048charge_pack_5,1.50%,$30.00,45%,$20.01,$24.99",
            "4,4000,86400,50,2048charge_pack_3,2048charge_pack_08,2048charge_pack_30,2048charge_pack_5,1.50%,$69.00,50%,$30.01,$29.99", 
            "5,5000,86400,50,2048charge_pack_3,2048charge_pack_08,2048charge_pack_39,2048charge_pack_5,1.50%,$75.00,48%,$36.01,$39.99"
        };

        private string[] UILanguageData =
        {
            "900001,BINGO",
            "900002,{0}st",
            "900003,Card{0}",
            "900004,TOTAL REWARDS",
            "900005,CLAIM",
            "900006,REWARDS",
            "900007,You get a chance to increase reward!",
            "900008,Claim more",
            "900009,Claim",
            "900010,Collect bubbles to redeem amazing prizes",
            "900011,Click anywhere to close",
            "900012,DREAM FUND",
            "900013,<color=#353533>${0}</color>",
            "900014,We will give you a <color=#353533>USD${0}</color> dream fund to help\nyou realize your dreams. so hurry up and get the\nfulfillment task!",
            "900015,CLAIM",
            "900016,You have Win cash!\nOnce you reach a certain\namount you can cash out",
            "900017,Collect $1000 to cash",
            "900018,Collect puzzle to exchange for lucky rewards.",
            "900019,Lucky Rewards",
            "900020,Click anywhere to close",
            "900021,SETTING",
            "900022,on",
            "900023,off",
            "900024,PRIVACY POLICY",
            "900025,GET TICKETS",
            "900026,The AD did not load successfully.",
            "900027,UID:{0} cashed out <color=#353533>${1}</color> by cash at {2}",
            "900028,1Card",
            "900029,2Cards",
            "900030,4Cards",
            "900031,PLAY GAME",
            "900032,{0} tickets",
            "900033,Ranking",
            "900034,REWARD TASK",
            "900035,Updated every 24 hours",
            "900036,<color=#353533>Convert User</color>",
            "900037,UID:{0} cashed out <color=#353533>${1}</color>\n{2}",
            "900038,WITHDRAW",
            "900039,Click here to fill in the account",
            "900040,Revise",
            "900041,My Money",
            "900042,Paypal",
            "900043,Cash App",
            "900044,${0}",
            "900045,USD",
            "900046,Need more {0} to cash out",
            "900047,RULES",
            "900048,1.   You can collect coins dollars.   iPhone puzzles by playing bingogame in Bingo Celebration.   And you may win the big jackpot of $500 in the slot games that can by triggered by bingo.\n2.   The rewards will be sent to You with in  nbusiness days (excepet of weekends).   Please wait Patiently.   If you don't recieve.  please contact us by mail at once.\n3.   Google is not a sponsor nor is involved in any way with these contests and sweepstakes.\n4.   Final interpretation is owned by [Bingo Celebration]",
            "900049,ORDER CONFIRMATION",
            "900050,whether to submit a ${0} order",
            "900051,YES",
            "900052,NO",
            "900053,You must watch more 50 viedos to\nActvate order",
            "900054,{0}d {1}h {2}m {3}s",
            "900055,{0}/50",
            "900056,QUICK TRACK",
            "900057,QUICK ACTIVATION",
            "900058,Pending",
            "900059,Successful",
            "900060,We provide you with two accelerated review methods.  \nYou can choose one of the methods to speed up the\norder review time.",
            "900061,<color=#353533>Conditions 1</color>",
            "900062,Watch <color=#353533>50</color> times anywhere in the game",
            "900063,<color=#353533>Conditions 2</color>",
            "900064,Pay <color=#353533>$2.99</color> platform handling fees and accelerate review",
            "900065,Pay",
            "900066,Cancel",
            "900067,The order has been\nsuccessfully activated go and\ncash out now !",
            "900068,CASH OUT",
            "900069,HANDLING FEE PAYMENT",
            "900070,Account",
            "900071,Amount",
            "900072,Fee",
            "900073,0.99",
            "900074,This fee is the platform manual review processing fee",
            "900075,Confirm",
            "900076,You have entered the bank\npre-approval stage and need to\npay bank fees.",
            "900077,TRANSACTION FEE",
            "900078,Payment platform",
            "900079,Receipt Account",
            "900080,<color=#353533>Receipt Amount</color>",
            "900081,Platform fee rate",
            "900082,Receipt amount",
            "900083,Limit discounts",
            "900084,<color=#353533>Save cost</color>",
            "900085,<color=#353533>Total Fee</color>",
            "900086,Dear player. we have entered your order into our system.\nWhen our system starts processing your <color=#353533>order number</color>.\nwe will contact you through your email account. Please\nsave your <color=#353533>order number</color>. Thank you for your\nparticipation.",
            "900087,ORDER",
            "900088,Order number ",
            "900089,BINGO{0} ",
            "900090,Channel  ",
            "900091,Date time",
            "900092,<color=#353533>Order processing</color>",
            "900093,WITHDRAWAL METHOD",
            "900094,Cash:",
            "900095,<color=#353533>Cash withdrawable:</color>",
            "900096,Please enter your name",
            "900097,Your e-mail",
            "900098,Your PayPal Account",
            "900099,Your Cash APP Account",
            "900100,Submit",
            "900101,Some of the information is error",
            "900102,Pay <color=#353533>$4.99</color> platform handling fees and accelerate review",
            "900103,REDEEM EXQUISITE GIFTS",
            "900104,{0}h {1}m {2}s",
            "900105,PRIZE DISPLAYd",
            "900106,<color=#353533>Order Processing</color>",
            "900107,LUCKY SPIN",
            "900108,SPIN",
            "900109,LUCKY BUBBLE",
            "900110,GET",
            "900111,During the activity.you may collect different amounts of Puzzles.which can be redeemed for the following.\n1. Lucky package\nDuring the game. you may get a random lucky pack. Watch the video to get this reward. Note that if you close the app or turn off the screen before watching the video you will get nothing.\n2. The way you get puzzles.the number of puzzles obtained in each way.and the rewards may change from time to time.please refer to the activity page in the app to view the latest event details.\n3.When redeeming\nrewards(except dice)you must accurately fill in your receiving information. otherwise You will be fully responsible for the failure of reward delivery. After we confirm the reward will be mailed to You within 3-15 working days.You need to comply with all applicable law sand be responsible for tax filing and payment.\n4.We will not provide any after-sales service for the rewards you get in the App. lf you have any questions about the award.Please contact the applicable manufacturer.\n5.lf there is a force majeure event or any change in circumstances beyond our control(including but not limited to strikes.God's actions.Policy changes.government actions.cyber attacks and system failures) resulting in suspension or adjustment of any activities. Please understand that we are obligated to compensate you for any expenses.and we do not assume any responsibility. If you are unable to participate in any activity due to your improper operation. network failure.tele-communications operator's failure or any third-Party reasons we\n are not obliged to compensate any costs. and we do not assume any legal responsibility.6. Please strictly abide by the rules of the event. lf any cheating or violations are found(including but not limited to using illegal tools to decode our services and hacking measures will be taken including but not limited to disqualification from participating in this event redeem any rewards obtaining redeemed rewards and or Using the application in this case no compensation of any reward.\n7.To the extent permitted by applicable laws. we have the right to adjust the rules of the event at any time. lf we decide to make a major decision.we will send advance notice of the adjustment in the App. The adjustment will take effect when the notice is issued or at the time specified in the notice. lf you do not agree to any adjustments. please do not participate in the activity again.\n8.We reserve the right to interpret activity rules and applicable laws and regulations within the scope permitted by the following activities.\n9. Our end user license agreement and privacy policy should also apply to this activity. lf there are discrepancies and inconsistencies between the policy and the rules of any particular activity the activity shall prevail.\n10. lf you have any questions or disputes about the rules. this activity or the application.please contact us.",
            "900112,Lucky Prizes",
            "900113,<color=#353533>My prize progress:</color>",
            "900114,<color=#353533>(Complete the progress and fill in the address to receive the gift.We will quickly deliver it to your side)</color>",
            "900115,Exchange",
            "900116,DELIVERY ADDRESS",
            "900117,FirstName*",
            "900118,LastName*",
            "900119,Phone*",
            "900120,Address*",
            "900121,Close",
            "900122,BINGO GIFTS",
            "900123,Double Rewards",
            "900124, collect <color=#353533>{0}</color> puzzles to redeem gifts",
            "900125,Lucky Reward",
            "900126,The platform requires you to pay the transaction fee to complete the withdrawal",
            "900127,Scratch",
            "900128,Task",
            "900129,PAUSE",
            "900130,Do you really want to give up?\nYou will miss the rest rewards.",
            "900131,QUIT",
            "900132,STAY",
            "900133,No Ads requsted",
            "900134,Not enough cash",
            "900135,DAILY TASK",
            "900136,GO",
            "900137,Play {0} bingo game",
            "900138,Play {0} lucky spin",
            "900139,Play {0} lucky bubble",
            "900140,Tomorrow  Bonus",
            "900141,DAILY BONUS",
            "900142,Day 1",
            "900143,Day 2",
            "900144,Day 3",
            "900145,Day 4",
            "900146,Day 5",
            "900147,Win IPHONE15 Pro",
            "900148,SPECIAL LUCKY WHEEL",
            "900149,Withdraw",
            "900150,Your order has been placed in the withdrawing queue.\nIt is being processed.",
            "900151,Ringht Now",
            "900152,Quickly Withdrawing",
            "900153,There are too many people withdrawing orders. and we are working hard to process it.\nYou can choose any of the ways below to speed up the refund process.\nOnce the conditions are met. we will refund the cash you spent immediately.",
            "900154,Pay <color=#353533>$4.99</color> platform handling fees and accelerate review",
            "900155,English",
            "900156,Fran?ais",
            "900157,Espa?ol",
            "900158,Português",
            "900159,Deutsch",
            "900160,Italiano",
            "900161,??",
            "900162,日本語",
            "900163,中文",
            "900164,Double",
            "900165,Buy the<color=#ffc600>${0}</color> <color=#5bed88>{1}</color>  with PayPal",
            "900166,Click below to open the payment service window and authorize your purchase.",
            "900167,Pay Now",
            "900168,Waiting for Approval",
            "900169,Confirm Purchase",
            "900170,Click below to complete your purchse.",
            "900171,Confirm",
            "900172,Purchase Complete",
            "900173,Thank yout for your purchase！",
            "900174,OK",
            "900175,watch videos to activate"
        };
    }
}

